﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MTQ.Web.Controllers
{
    public class HandlerErrorAttribute : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext context)
        {
            base.OnException(context);
            //context.ExceptionHandled = true;

            WriteLog(context, context.Exception);
            //var url = context.HttpContext.Request.Path;
            //var msg = url + context.Exception.Message;
           // new LogApp().WriteDbLog(msg);
        }

        private void WriteLog(ExceptionContext context,Exception ex)
        {
            object listUserAction = context.HttpContext.Session["UserInfo"];
            string User_UserName = string.Empty;
            if (listUserAction != null)
            {
                var userInfo = listUserAction as MTQ.Model.Base_UserInfo;
                User_UserName = userInfo.User_UserName;
            }
          
           

            System.Threading.Tasks.Task.Run<bool>(() =>
            {
                var t1 = System.Threading.Tasks.Task.Run(() =>
                {
                    BLL.Log_ErrorService.SaveRequestErrorLog(context.HttpContext.Request, User_UserName, ex);
                });
                return true;
            });
            if (context == null)
                return;
            //var log = LogFactory.GetLogger(context.Controller.ToString());
            //log.Error(context.Exception);
        }
    }
}
